package com.lianzhihui.romeex.mvp.model;

import android.content.Context;

import com.lianzhihui.romeex.bean.InvitationInfoBean;
import com.lianzhihui.romeex.bean.UserInfoBean;
import com.lianzhihui.romeex.net.APIConstant;
import com.lianzhihui.romeex.net.HttpManager;
import com.lianzhihui.romeex.net.HttpManagerCallback;
import com.lianzhihui.romeex.net.ResultData;
import com.lianzhihui.romeex.utils.GsonUtil;
import com.lianzhihui.romeex.utils.LogUtil;
import com.zhouyou.http.exception.ApiException;
import com.zhouyou.http.model.HttpParams;

/**
 * @ProjectName: romeex
 * @Package: com.lianzhihui.romeex.mvp.model.base
 * @ClassName: InvitationModellmp
 * @Description: java类作用描述
 * @Author: zhanghong
 * @CreateDate: 2020/11/9 18:18
 * @UpdateUser: 更新者：
 * @UpdateDate: 2020/11/9 18:18
 * @UpdateRemark: 更新说明：
 * @Version: 1.0
 */
public class InvitationModelImp {


    private Context context;
    InvitationModelInterface model;

    public InvitationModelImp(Context context, InvitationModelInterface model) {
        this.context = context;
        this.model = model;
    }

    public void requestUserInfo() {
        HttpParams params = new HttpParams();
        new HttpManager(context, new HttpManagerCallback() {
            @Override
            public void onSuccess(ResultData o) {
                if (o.getCode() == 200 && o.getData() != null) {
                    UserInfoBean bean = GsonUtil.GsonToBean(o.getData(), UserInfoBean.class);
                    model.responseSuccess(bean);
                } else {
                    model.responseFailed(o.getCode(), o.getMsg());
                }
            }

            @Override
            public void onError(ApiException e) {
//                ToastUtils.showShort(MyApplication.mContext.getResources().getString(R.string.text_net_error));
                model.responseFailed(-1, "error");
            }
        }).post(APIConstant.USER_INFO, params);
    }

    public void requestBindInfo() {
        HttpParams params = new HttpParams();
        new HttpManager(context, new HttpManagerCallback() {
            @Override
            public void onSuccess(ResultData o) {
                if (o.getCode() == 200 && o.getData() != null) {
                    InvitationInfoBean bean = GsonUtil.GsonToBean(o.getData(), InvitationInfoBean.class);
                    model.responseBindInfoSuccess(bean);
                } else {
                    model.responseBindInfoFailed(o.getCode(), o.getMsg());
                }
            }

            @Override
            public void onError(ApiException e) {
                LogUtil.error("InvitationModelImp",e.toString());
//                ToastUtils.showShort(MyApplication.mContext.getResources().getString(R.string.text_net_error));
                model.responseBindInfoFailed(-1, "error");
            }
        }).post(APIConstant.BIND_INFO, params);
    }
}
